<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>不定宽盒子垂直居中</title>
    <style>
        /* 方式一 父盒子设置flex布局 */
        /* body{
            display: flex;
            justify-content: center;
            align-items: center;
            height: 600px;
        } */
        #app{
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            margin: auto;
            width: 150px;
            height: 150px;
            background-color: hotpink;
        }
    </style>
</head>
<body>
    <div id="app">

    </div>
</body>
</html>